Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: Add compile time error on 64 bit platforms #11110

Merged

Conversation

nordic-krch
Copy link
Contributor

Logger is designed with assumption that address fit in 32 bits.
Added explicit compilation error on 64 bit platforms.

Signed-off-by: Krzysztof Chruscinski [email protected]

@jakub-uC jakub-uC requested a review from carlescufi November 5, 2018 14:21
@codecov-io
Copy link

codecov-io commented Nov 5, 2018

Codecov Report

Merging #11110 into master will increase coverage by 0.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11110      +/-   ##
==========================================
+ Coverage   52.96%    53.1%   +0.13%     
==========================================
  Files         218      218              
  Lines       26840    26853      +13     
  Branches     5949     5950       +1     
==========================================
+ Hits        14217    14259      +42     
+ Misses      10187    10162      -25     
+ Partials     2436     2432       -4
Impacted Files Coverage Δ
include/logging/log_core.h 100% <ø> (ø) ⬆️
include/logging/log_msg.h 90.9% <0%> (+1.81%) ⬆️
misc/printk.c 88.55% <0%> (+3.09%) ⬆️
subsys/logging/log_core.c 71.68% <0%> (+3.62%) ⬆️
subsys/logging/log_output.c 72.68% <0%> (+8.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae4d761...91d8d52. Read the comment docs.

@@ -15,6 +15,10 @@
extern "C" {
#endif

#ifdef __LP64__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #9522 the pointers are 32-bit even though the system is running in 64 bit. Would this check work with that PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LP64 by definition, indicates that longs and pointers are 64-bit.
http://www.unix.org/version2/whatsnew/lp64_wp.html

I haven't tested this, but since the x86_64 port runs with 32-bit pointers, I imagine we should be fine, the compiler shouldn't be defining this macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, x86_64 won't hit this because it's running in the x32 ABI. But... I mean, it's x32 until it's not. A very reasonable future would have us running in a fully 64 bit mode on platforms like x86 and RISC-V. Not a reason to reject this patch if there are known word size issues, but we'll eventually want to fix the underlying issue.

@andyross
Copy link
Contributor

andyross commented Nov 5, 2018

I'd prefer to see this done in terms of a sizeof() comparison over the types you actually care about instead of relying on the toolchain to correctly set LP64. We have a lot of oddball toolchains, and I bet somewhere in the world there's a "64 bit" compiler that doesn't set this.

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Forgot vote: just barely across my tolerance for a -1. Feel free to override if someone feels strongly.)

Logger is designed with assumption that address fit in 32 bits.
Added explicit compilation error on 64 bit platforms.

Signed-off-by: Krzysztof Chruscinski <[email protected]>
@nordic-krch
Copy link
Contributor Author

changed to UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFUL

@@ -15,6 +15,10 @@
extern "C" {
#endif

#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFUL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have BUILD_ASSERT_MSG() macro that could be used here, so something like this

BUILD_ASSERT_MSG(sizeof(void *) == 4, "Logger does not support 64 bit architecture");

You seem to be using it already in log_msg.h. I have no preference for this so this proposal is ok too.

@carlescufi
Copy link
Member

@andyross can you take another look now that this uses UINTPTR_MAX?

Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes my concern about failing to detect oddball "64 bit but not LP64" platforms.

Note that Jukka's suggestion about using a build assert (which can make use of sizeof() as it happens in the compiler not the preprocessor) is still a better idea IMHO

@carlescufi carlescufi merged commit c036d2f into zephyrproject-rtos:master Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants